using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class RoleDetailModel : ModelBase
    {
        public RoleDetailModel()
        {
            client.GetSingleRoleCompleted += DoGetSingleRoleCompleted;
            client.InsertRoleCompleted += DoInsertRoleCompleted;
            client.UpdateRoleCompleted += DoUpdateRoleCompleted;
            client.GetAuthorizationCollectionCompleted += DoGetAuthorizationCollectionCompleted;
        }

        #region GetAuthorizationCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Authorization>> GetAuthorizationCollectionCompleted;

        public int GetAuthorizationCollectionAsync()
        {
            client.GetAuthorizationCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        private void DoGetAuthorizationCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Authorization> e)
        {
            if (GetAuthorizationCollectionCompleted != null)
            {
                GetAuthorizationCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region UpdateRole

        public event EventHandler<FeedbackCompletedEventArgs> UpdateRoleCompleted;

        public int UpdateRoleAsync(Role data)
        {
            client.UpdateRoleAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUpdateRoleCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UpdateRoleCompleted != null)
            {
                UpdateRoleCompleted(sender, e);
            }
        }

        #endregion

        #region InsertRole

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertRoleCompleted;

        public int InsertRoleAsync(Role data)
        {
            client.InsertRoleAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoInsertRoleCompleted(object sender, SingleFeedbackCompletedEventArgs<int> e)
        {
            if (InsertRoleCompleted != null)
            {
                InsertRoleCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleRole

        public event EventHandler<SingleFeedbackCompletedEventArgs<Role>> GetSingleRoleCompleted;

        public int GetSingleRoleAsync(int objID)
        {
            client.GetSingleRoleAsync(objID);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleRoleCompleted(object sender, SingleFeedbackCompletedEventArgs<Role> e)
        {
            if (GetSingleRoleCompleted != null)
            {
                GetSingleRoleCompleted(sender, e);
            }
        }

        #endregion
    }
}